package com.stars.home.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.hwangjr.rxbus.annotation.Subscribe
import com.hwangjr.rxbus.annotation.Tag
import com.stars.home.adapter.CustomerOrderListAdapter
import com.stars.home.base.MBRFragment
import com.stars.home.config.ConfigRx
import com.stars.home.databinding.FragmentCustomerOrderListBinding
import com.stars.home.model.CompreBean
import com.stars.home.vmodel.CustomerOrderListVModel
import com.trailer.base.net.IResp

/**
 *on 2021/5/7
 */
class CustomerOrderListFragment: MBRFragment<CustomerOrderListVModel, CustomerOrderListAdapter, FragmentCustomerOrderListBinding>() {

    override fun __before(savedInstanceState: Bundle?) {
        super.__before(savedInstanceState)
        vm.order_state = arguments?.getString("order_state")

    }
    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)


    }

    override fun vmClass(): Class<CustomerOrderListVModel> {
        return CustomerOrderListVModel::class.java
    }
    override fun binding(inflater: LayoutInflater, container: ViewGroup?): FragmentCustomerOrderListBinding {
       return FragmentCustomerOrderListBinding.inflate(layoutInflater)
    }



    override fun initAdapter(): CustomerOrderListAdapter {
       return CustomerOrderListAdapter(vm)
    }

    override fun onListReceive(res: IResp<*>) {
        super.onListReceive(res)

        if (null != res) {

            var list = res.data() as List<CompreBean>
            if (list.isEmpty() && vm.repository().page == 1) {

                binding.listEmpty.visibility = View.VISIBLE
            } else {
                binding.listEmpty.visibility = View.GONE
            }

        }
    }

    override fun title(): String? {
        return null
    }

    override val isRxbus: Boolean
        get() = true

    @Subscribe(tags = [Tag(ConfigRx.REFRESH_PAY)])
    fun setRefreshPay(position: String) {

        onRefresh()
    }
    @Subscribe(tags = [Tag(ConfigRx.REFRESH_LIST)])
    fun setRefreshList(position: String) {
        onRefresh()
    }

}
